//
//  UIButton+Extension.swift
//  Weibo
//
//  Created by 张婷 on 15/10/16.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

extension UIButton {
    
    ///  遍历构造函数
    ///
    ///  - parameter imageName:     设置普通状态 & 高亮状态 图像名称
    ///  - parameter backImageName: 设置普通状态 & 高亮状态 背景图像名称
    ///
    ///  - returns: UIButton
    convenience init(imageName: String, backImageName: String) {
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        sizeToFit()

    }
    
    ///  便利构造函数
    ///
    ///  - parameter title:         名称
    ///  - parameter color:         名称字体颜色
    ///  - parameter backImageName: 背景图像名称
    ///
    ///  - returns:  UIButton
    convenience init(title: String, color: UIColor = UIColor.darkGrayColor(), backImageName: String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
    }
    
    ///  便利构造函数
    ///
    ///  - parameter title:     文字
    ///  - parameter fontSize:  文字大小
    ///  - parameter color:     文字颜色
    ///  - parameter imageName: 图像名称
    ///
    ///  - returns:  UIButton
    convenience init(title: String, fontSize: CGFloat, color: UIColor, imageName: String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setImage(UIImage(named: imageName), forState: .Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
}
